package com.flyduck.vueshop.auth.h5.controller;

import com.flyduck.vueshop.auth.h5.service.H5LoginService;
import com.flyduck.vueshop.auth.h5.vo.H5CaptchaRespVO;
import com.flyduck.vueshop.auth.h5.vo.H5LoginReqVO;
import com.flyduck.vueshop.auth.h5.vo.H5LoginRespVO;
import com.flyduck.vueshop.auth.h5.vo.H5RegisterReqVO;
import com.flyduck.vueshop.common.core.lang.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * H5LoginController
 * </p>
 *
 * @author flyduck
 * @since 2024-07-10
 */
@RestController
@RequestMapping("/auth/h5")
public class H5LoginController {

    @Resource
    private H5LoginService h5LoginService;

    @PostMapping("/login")
    public Result<H5LoginRespVO> login(@Validated @RequestBody H5LoginReqVO h5LoginReqVO){
        H5LoginRespVO h5LoginRespVO = h5LoginService.login(h5LoginReqVO);
        return Result.success(h5LoginRespVO);
    }

    @GetMapping("/getCaptcha")
    public Result<H5CaptchaRespVO> getCaptcha(){
        H5CaptchaRespVO h5CaptchaRespVO = h5LoginService.getCaptcha();
        return Result.success(h5CaptchaRespVO);
    }

    @PostMapping("/register")
    public Result<Void> register(@Validated @RequestBody H5RegisterReqVO h5RegisterReqVO){
        h5LoginService.register(h5RegisterReqVO);
        return Result.success();
    }
}
